package CliGui;

import javax.swing.*;

import java.awt.*;

import static java.lang.Thread.sleep;

/*
事件监听：
    两个按钮和键盘回车
 */

//这是等待服务器连接数大于2时的窗口
public class WaitingGui extends JFrame {
    private static boolean flag = true;
    public WaitingGui() throws InterruptedException {
        init();
    }

    public void init() throws InterruptedException {
        JTextField waitText = new JTextField("正在等待连接服务器的客户端数>=2中");
        JTextField waitPoint = new JTextField(".");
        waitText.setEditable(false);
        waitPoint.setEditable(false);

        //水平居中
        waitText.setHorizontalAlignment(SwingConstants.CENTER);
        waitPoint.setHorizontalAlignment(SwingConstants.CENTER);

        //设置字体
        waitText.setFont(new Font("宋体",Font.PLAIN,20));
        waitPoint.setFont(new Font("宋体",Font.PLAIN,20));

        //关闭文本框
        waitText.setBorder(null);
        waitPoint.setBorder(null);

        String[] waitP = {".","..","...","....",".....","......"};
        setTitle("聊天软件");
        setBounds(300,300,400,300);

        setLayout(new GridLayout(2,1));


        add(waitText);
        add(waitPoint);

        setVisible(true);

        int i=1;
        while(true){
            sleep(1000);
            waitPoint.setText(waitP[i]);
            i = (i+1)%6;
            if(!flag){
                break;
            }
        }
        dispose();
    }

    public static void setFlagFalse(){
        flag = false;
    }

}
